package com.grad.why.studentsystem.util;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Util {
    public static String formGetCellType(Cell cell){
        String value=null;
        try{
            if(cell.getCellType()==cell.CELL_TYPE_BLANK){
                value="";
            }else if(cell.getCellType()==cell.CELL_TYPE_ERROR){
                value="";
            }else if(cell.getCellType()==cell.CELL_TYPE_FORMULA){
                value=cell.getCellFormula();
            }else if(cell.getCellType()==cell.CELL_TYPE_NUMERIC){
                if (DateUtil.isCellDateFormatted(cell)) {
                    Date tempValue = cell.getDateCellValue();
                    SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    value = simpleFormat.format(tempValue);
                }else {
                    value = String.valueOf(cell.getNumericCellValue());
                }
            }else if(cell.getCellType()==cell.CELL_TYPE_STRING){
                value=cell.getStringCellValue();
            }else{
                SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                value=simpleFormat.format(cell.getDateCellValue());
            }
        }catch(Exception e){
            e.printStackTrace();
        }
        return value;
    }

    public static boolean checkStrIsNumber(String sid){
        char[] chars = sid.toCharArray();
        boolean flag = true;
        for(char c : chars){
            if(!Character.isDigit(c)){
                flag = false;
                break;
            }
        }
        return true;
    }
}
